package com.ttn.util;

import java.util.Locale;

import javax.el.ELContext;
import javax.el.ELException;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.jsf.el.SpringBeanFacesELResolver;

public class MySpringBeanFacesELResolver extends SpringBeanFacesELResolver {
	private static final Logger logger = Logger
			.getLogger(MySpringBeanFacesELResolver.class);

	
	@Override
	public Object getValue(ELContext elContext, Object base, Object property)
			throws ELException {
		if (base instanceof MessageSource && property instanceof String) {
			String result = "";
			try{
			result = ((MessageSource) base).getMessage(
					(String) property, null,Locale.ENGLISH);
			logger.debug(" Result for " + property + ": " + result);
			if (null != result) {
				elContext.setPropertyResolved(true);
			}
			}catch (Exception e){
				result =  "?"+property+"?";
				elContext.setPropertyResolved(true);
			}
			return result;
		}
		return super.getValue(elContext, base, property);
	}

	
}